package com.cdj.common.behavior;


import com.cdj.common.ILoadingBehavior;
import com.cdj.common.IResultCallBackBehavior;

/**
 * ---------------------------------------------------------<br />
 * desc：<br />
 * author：chendeji <br />
 * date：2021/6/22<br />
 * email：18701434169@163.com<br />
 * qq: 781571323
 * wx: melody_2009
 * ---------------------------------------------------------<br />
 */
public abstract class BaseLoadingBehavior<T, Result> implements ILoadingBehavior {

    protected ILoadingBehavior wrap;
    protected IResultCallBackBehavior<Result> behavior;
    protected T parame;

    public BaseLoadingBehavior(){}
    public BaseLoadingBehavior(ILoadingBehavior defualt) {
        this.wrap = defualt;
    }

    public void setParame(T parame) {
        this.parame = parame;
    }

    public abstract void request();

    public void setCallBackBehavior(IResultCallBackBehavior<Result> behavior) {
        this.behavior = behavior;
    }

    protected void callBack(Result result) {
        if (this.behavior != null) {
            this.behavior.callBack(result);
        }
    }

    @Override
    public void onLoading() {
        if (this.wrap != null) {
            this.wrap.onLoading();
        }
    }

    @Override
    public void finishLoad() {
        if (this.wrap != null) {
            this.wrap.finishLoad();
        }
    }

}
